<?php
declare (strict_types = 1);

namespace app\mall\model;

use app\mall\enum\OpUserEnum;
use app\mall\model\traits\OpUserTrait;
use think\Model;

/**
 * @mixin Model
 * @property OpUserEnum user_type_enum
 * @property string user_type_text
 */
class MallOrderLog extends Model
{
    use OpUserTrait;

    public function getUserTypeTextAttr($key, $data)
    {
        return $this->user_type_enum->getZhName();
    }

    public function getUserTypeEnumAttr($key, $data)
    {
        return new OpUserEnum($data['user_type']);
    }

    public function setImagesAttr($value, $data)
    {
        return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : '{}';
    }

    public function getImagesAttr($value, $data)
    {
        return $value ? json_decode($value, true) : [];
    }
}
